package com.leeyu.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class HeaderConfig {

    public static final String HEADER_EXCHANGE = "header-exchange";

    public static final String HEADER_QUEUE = "header-queue";

    @Bean
    public Exchange headerExchange() {
        return ExchangeBuilder.headersExchange(HEADER_EXCHANGE).build();
    }

    @Bean
    public Queue headerQueue() {
        return QueueBuilder.durable(HEADER_QUEUE).build();
    }

    @Bean
    public Binding headerBinding(Exchange headerExchange, Queue headerQueue) {
        HashMap<String, Object> arguments = new HashMap<>();
        arguments.put("x-match","all");
        arguments.put("name","abc");
        arguments.put("value","123");
        return BindingBuilder.bind(headerQueue).to(headerExchange).with("").and(arguments);
    }
}
